﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

public partial class Example2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument empDoc = new XmlDocument();
        Response.ContentType = "text/xml";
        try
        {
            //Load the XML from a String
            empDoc.LoadXml("<?xml version=\"1.0\" ?>" +
                           "<employees>" +
                           "<employee id='1'>" +
                           "<name><firstName>Nancy</firstName>" +
                           "<lastName>Davolio</lastName>" +
                           "</name><city>Seattle</city>" +
                           "<state>WA</state><zipCode>98122</zipCode>" +
                           "</employee></employees>");
            //Save the XML data onto a file                    
            empDoc.Save(Server.MapPath("Employees.xml"));
        }
        catch (XmlException xmlEx)
        {
            Response.Write("XmlException: " + xmlEx.Message);
        }
        catch (Exception ex)
        {
            Response.Write("Exception: " + ex.Message);
        }
    }
}